package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.OrderDao;
import com.tequila.core.service.OrderService;
import com.tequila.domain.dto.OrderDto;
import com.tequila.domain.entity.Order;
import com.tequila.domain.query.OrderQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    public static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);

    @Resource
    private OrderDao orderDao;

    @Override
    public Pagination<OrderDto> queryPageListByParam(OrderQuery query) {
        Assert.assertNotNull(query);
        int total = orderDao.queryPageCountByParam(query);

        List<OrderDto> list = Lists.newArrayList();
        if (total > 0) {
            list = orderDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public OrderDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        Order order = orderDao.queryById(id);
        OrderDto orderDto = new OrderDto();
        BeanHelper.copyProperties(orderDto,order);
        return orderDto;
    }

    @Override
    public List<OrderDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return orderDao.queryByIdList(idList);
    }

    @Override
    public List<OrderDto> queryListByParam(OrderQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return orderDao.queryListByParam(query);
    }


    @Override
    public Long insert(Order entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        orderDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(Order entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        orderDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(Order param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return orderDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(Order param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return orderDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return orderDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return orderDao.deleteByIdList(idList);
    }
}
